package com.prdiot.poetry.dao;

import com.prdiot.poetry.domains.Author;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;


public interface AuthorRepository extends JpaRepository<Author, Integer> {

    @Query("select a from Author a where a.authorName like %?1%")
    Page<Author> searchByKey(@Param("key") String key, Pageable pageable);

    @Query(value = "select * from authors ORDER BY poems desc LIMIT ?1", nativeQuery=true)
    List<Author> getTopAuthors(int num);

    Optional<Author> findByAuthorId(String authorId);
}
